/*
  Author: Sheila Tabuena
  Filename: loadPage.js
  Project: Palo Alto Bicycle Club
  Date Created: JUN-3-2009

  Contains functions to support Palo Alto Bicycle Club home page, which contains
  admin generated announcements and other text.

    $(document).ready(function() -- Begins the process that will build the page, calls function buildPage()
    buildPage()-- This function is called by onload, it builds the page, filling out
                  the title area, the footer area, then calling functions to load the home page
                  tab, the weather area, and the user-generated announcements.

    setHead(newHead)--This function changes the major page head in the page title area
                 
    loadHome()--called on inital load or tab switch to home tab
                     It loads the latest Admin Generated Announcements
    loadNews()--This function is called on tab switch to Newsletter tab
                Changes head and builds newsletter content
    loadJoin()--called on tab switch to Membership tab
                Builds the content for the Membership tab
    loadLibrary()--called on tab switch to Route Library
                   Builds the content for the route library tab
    loadUserAnnounce()--called as the page is built to create the 
                        User Posted Annoucement Area
    showTeam()--This function displays an alert with the team members
                     */


// Begins the process that will build the page
$(document).ready(function() 
{
   buildPage();
 });

// This function is called by onload, it builds out the page, including the footer
function buildPage()
{
	$("#logo").attr("src","css/BikeLogo.jpg");
	$("<h1>Welcome</h1>").attr("id","tabTitle").prependTo("#container");
	$("<img>").attr("src","css/BikeLogo.jpg").prependTo("#container");
  $("<a>Contact Us</a>").attr("id","c_ref").attr("href","mailto:webmaster@pabc.com").appendTo("#footer");
  $("<a>About Us</a>").attr("id","a_ref").attr("href","javascript:showTeam();").appendTo("#footer");
   $("#homeTab").click(function() 
   {
      loadHome();
   });
   $("#newsTab").click(function() 
   {
      loadNews();
   });
   $("#joinTab").click(function() 
   {
      loadJoin();
   });
   $("#libraryTab").click(function() {
      loadLibrary();
   });
// loadWeather();
  loadUserAnnounce();  
  loadHome();
   $("#storeTab").click(function() {
      loadStore();
   });
}

// This function changes the major page head in the page title area
function setHead(newHead)
{
	hNode = document.getElementById("tabTitle");
	hNode.firstChild.data = newHead;
}

// This function is called on inital load or tab switch to home tab
// It loads the latest Admin Generated Announcements
function loadHome()
{
  setHead("Welcome To Our Club!");
  getAdminAnnounce();
  var homeNode = document.getElementById("home");
  homeNode.innerHTML="";
  addJqNode(homeNode,"h1","homeBody","Welcome to Palo Alto Bicycle Club");
  getCalendar();
 }

// This function is called on tab switch to Newsletter tab
function loadNews()
{
  setHead("PABC Newsletter");
  var divNode = document.getElementById("news");
  divNode.innerHTML="";
  addJqNode(divNode,"h1","h1_n1","The Flat Tyre!");
  getNewsLetter();
  // MASON: add a call to your function right here
}

// This function is called on tab switch to Membership tab
// Builds the content for the Membership tab
function loadJoin()
{
  setHead("PABC Membership Form");
  var divNode = document.getElementById("join");
  divNode.innerHTML="";
  addJqNode(divNode,"h1","h1_j1","Join, Come and Have Fun!");
  getMembership();  
  // MASON: add a call to your function right here
}

// This function is called on tab switch to Route Library
// Builds the content for the route library tab
function loadLibrary()
{
  setHead("PABC Route Library");
  var divNode = document.getElementById("library");
  divNode.innerHTML="";
  addJqNode(divNode,"h1","h1_l1","Pick a Bike Ride from our Route Library");
  getRouteLibrary();
}

// This function is called on tab switch to Route Library
// Builds the content for the route library tab
function loadStore()
{
  setHead("PABC Store");
  var divNode = document.getElementById("store");
  divNode.innerHTML="";
  addJqNode(divNode,"h1","h1_s1","All sales benefit the club!");
  addJqNode(divNode,"div","storeDiv","");
  getStore(1);
}

// This function is called as the page is built to create the 
// User Posted Annoucement Area
function loadUserAnnounce()
{
	divNode = $("#userAnnounce");
  divNode.attr("class","ui-state-highlight ui-corner-all");
  addJqNode(divNode,"h4","notHead","Notices from Members"); 
  nNode = addJqNode(divNode,"div","notices","");
  nNode.attr("class","ui-state-highlight ui-corner-all");
  iNode = addJqNode(divNode,"input","uaInput","");
  iNode.attr("size","38");
  bNode = addJqNode(divNode,"button","uaAdd"," Add Notice ");
  bNode.attr("class","ui-state-default ui-corner-all");
  bNode.attr("onclick","doAdd();");
  getNotices(doNoticeTable);
}

// This function displays an alert with the team members
function showTeam(){
	alert('This site was created by Julie Hu, Albert Wu, Mason Leung and Sheila Tabuena');
}




